﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Web;
using System.Web.Mvc;
using RBS.Core.Model;

namespace RBS.Web.Controllers
{
    public class BaseController : Controller
    {


        public RBS.Core.Model.U_User CurrentUser
        {
            get
            {
                if (!Request.IsAuthenticated)
                {
                    ToLogin(); 
                } 
                else{
                    U_User user = null;
                    if (Session["User"] == null && User.Identity.Name!="")
                    {
                        user = new RBS.Core.BLL.U_User().GetModelByCache(Convert.ToInt32(User.Identity.Name)); 
                        Session["User"] = user;
                    } 
                    else
                      user = (RBS.Core.Model.U_User)Session["User"];
                    return user;
                }
                return null;
            }
        } 
        public void ToLogin()
        {
            Response.Redirect("~/Login?redirectUrl="+Request.RawUrl);
            return;
        }

        public ContentResult AlertMsg(string msg)
        {
            return AlertMsg(msg, null);
        } 
        public ContentResult AlertMsg(string msg, string url)
        {
            var stcript = "$.dialog.alert('" + msg + "');";
            if(url!=null){
                stcript += "window.location.href='" + url + "'";
            }
            return Content(stcript, "application/x-javascript"); 
        }

    }
}
